import { observable, action } from 'mobx';

import ListBaseStore from './ListBaseStore';
import * as DiscussManageApis from '../apis/discussManage';
import { WeaLocaleProvider } from 'ecCom';
import { WeaLogView } from 'comsMobx';

const getLabel = WeaLocaleProvider.getLabel;
const { LogStore } = WeaLogView;

/**
 * 内容审批Store
 */
export default class DiscussApprovalStore extends ListBaseStore {
	@observable logStore = new LogStore();
	@observable deleteDialogVisible = false;

	// 内容删除参数值
	@observable
	formValus = {
		discussIds: '',
		isDeleteAll: 1,
	}

	constructor() {
		super();

		this.title = getLabel(32575, '内容审批');
		this.selectedKey = 0;
	}

	@observable status = {
		targetId: '',
		logType: '', // 日志相关参数
		logSmallType: '',
	}

	@action doInit = () => {
		this.doBaseInit();
		this.selectedKey = 0;
    this.initConditionDatas(); // 初始化高级搜索区域
    this.doTableLoading(); // 初始化列表
	}


	// 设置checkbox值
	@action setIsDeleteAll = (value = 1) => {
		this.formValus.isDeleteAll = value;
	}

	// 打开 或 隐藏删除对话框
	@action showDeleteDialog = (mode, values = '') => {
		this.deleteDialogVisible = mode;

		let discussIds = mode ? values : '';
		this.formValus.discussIds = discussIds;
		this.formValus.isDeleteAll = 1; // 默认是选中状态
	}


	// 加载列表数据
	@action doTableLoading = (params) => {
		this.showLoading(true);

		let resultParams = this.getFormParams();

		let commonParams = {
			datetype: this.selectedKey, // 时间类型
		};

		resultParams = { ...resultParams, ...commonParams, ...params };

		DiscussManageApis.getCoworkDiscussApprovalList(resultParams).then(
			(result) => {
				this.status = { ...this.status, logType: result.logType, logSmallType: result.logSmallType };
				const sessionkey = result.sessionkey;
				this.sessionkey = sessionkey;
				this.comsWeaTableStore.getDatas(sessionkey, 1);

				this.showLoading(false);
			},
		);
	}

	// 初始化收藏的帖子页面查询条件
	@action initConditionDatas = (params) => {
		DiscussManageApis.getCoworkDiscussApprovalShareCondition(params).then(
			(result) => {
				this.topTab = result.topTab;
				this.conditioninfo = result.conditioninfo;

				this.initFormFields(this.conditioninfo); // 一定要先初始化initFormFields表单对象
			},
		);
	}

	// 批准、批量批准
	@action batchDiscussApprove = (params, callback) => {
		DiscussManageApis.batchDiscussApprove(params).then(
			() => {
				if (callback && typeof callback === 'function') {
					callback();
				}
			},
		);
	}

	// 删除、批量删除
	@action batchDiscussDel = (params, callback) => {
		DiscussManageApis.batchDiscussDel(params).then(
			() => {
				if (callback && typeof callback === 'function') {
					callback();
				}
			},
		);
	}
}
